/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package questionbook.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author stefanstift
 */
public class Md5 {

    public Md5() {
    }

    public String getMd5Hash(String password) {

        MessageDigest md5 = null;

        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
        }

        md5.reset();
        md5.update(password.getBytes());
        byte[] result = md5.digest();

        StringBuffer hexString = new StringBuffer();

        for (int i = 0; i < result.length; i++) {
            if (result[i] <= 15 && result[i] >= 0) {
                hexString.append("0");
            }
            hexString.append(Integer.toHexString(0xFF & result[i]));
        }

        return hexString.toString();
    }
}
